<?php
class Controller_Home extends Controller_User_Template {
	public function action_index() {
		
		$promotionsview = View::factory('template/currentpromotions');
		
		$promotions = ORM::factory('promotion')
		->where('starting_date', '<=', strtotime("now"))
		->and_where('ending_date', '>=', strtotime("now"))
		->order_by('ending_date', 'asc')
		->limit(3)
		->find_all();
		$promotionsview->set('promotions', $promotions);
		
		$this->template->currentpromotions = $promotionsview;
	}
	
	public function action_promotinos() {
		$current_time = new DateTime();
		$current_timestamp = $current_time->getTimestamp();
		$promotions = ORM::factory('promotion')
		->where('starting_date', '<=', $current_timestamp)
		->and_where('ending_date', '>=', $current_timestamp)
		->find_all();
		$promotionsview->set('promotions', $promotions);
		
		$this->template->currentpromotions = $promotionsview;
			
	}
	
}